package com.atguigu.gulimall.search.controller;

import com.atguigu.common.to.SkuEsModel;
import com.atguigu.common.utils.R;
import com.atguigu.gulimall.search.service.ProductSaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("search")
public class ElasticSaveController {

    @Autowired
    private ProductSaveService productSaveService;

    @PostMapping("save/product")
  public R productUp( @RequestBody List<SkuEsModel> skuEsModels) {
        Boolean  meassge =false;
        try {
         meassge  =  productSaveService.productStatusUp(skuEsModels);
        } catch (IOException e) {
            return R.error(e.getMessage());
        }
        if (!meassge){
            R.error();
        }
        return R.ok();
    }
}
